package com.itheima.a03;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: AirMan
 * @date: 2025/4/9 13:54
 * @description: TemplateMethod
 */
public class TemplateMethod {


    public static void main(String[] args) {

        MyBeanFactory myBeanFactory = new MyBeanFactory();
        myBeanFactory.addBeanPostProcessor(() -> System.out.println("@Auworied 依赖注入增强..."));
        myBeanFactory.addBeanPostProcessor(() -> System.out.println("@Resource 依赖注入增强..."));
        myBeanFactory.getBean();

    }

    static class MyBeanFactory {

        static List<PostProcessProperties> postProcessProperties = new ArrayList<>();

        public void getBean() {
            System.out.println("创建Bean...");
            System.out.println("依赖注入...");
            for (PostProcessProperties postProcessProperty : postProcessProperties) {
                postProcessProperty.inject();
            }
            System.out.println("初始化...");
        }

        public void addBeanPostProcessor(PostProcessProperties processor) {
            postProcessProperties.add(processor);
        }

    }

    interface PostProcessProperties {
        void inject(); // 接口，需要实现类自己实现依赖注入逻辑
    }

}
